using System;
using System.Configuration;
using Npgsql;
using System.Data;

namespace databaselib
{
	public class database_loading
	{
		string connectionstring;
		
		public database_loading()
		{
			//connectionstring= System.Configuration.ConfigurationManager.AppSettings["connectionstr"].ConnectionString; 
			connectionstring="SERVER=localhost;Database=accounts;Integrated Security=false;User Id=postgres;Password=password;";
			//connectionstring=ConfigurationSettings.AppSettings["connectionstr"];
		}
		public string insertvalues(string fnname,string fnmailid,string fnaddr,string fnyrstart,string fnyrend,string fnpassword,string fncmpnyid)
		{
			Npgsql.NpgsqlConnection con=new Npgsql.NpgsqlConnection(connectionstring);
			try
			{
				con.Open();
				Npgsql.NpgsqlCommand cmd=new Npgsql.NpgsqlCommand("insert into company(name,mailid,addr,yrstart,yrend,password,cmpnyid) values('"+fnname+"','"+fnmailid+"','"+fnaddr+"','"+fnyrstart+"','"+fnyrend+"','"+fnpassword+"','"+fncmpnyid+"')");
				//Npgsql.NpgsqlCommand cmd=new Npgsql.NpgsqlCommand("insert into company values('"+a.ToString()+"','"+b.ToString()+"','"+c.ToString()+"','"+d.ToString()+"','"+e.ToString()+"','"+f.ToString()+"'");
				cmd.Connection=con;
			    cmd.ExecuteNonQuery();
			}
			catch(Exception ex)
			{
		return ex.Message;
			}
				
				finally
			{
				con.Close();
			}
			return "success";
		}
		public DataTable listdata()
		{
			NpgsqlConnection conn=new NpgsqlConnection(connectionstring);
			NpgsqlDataAdapter da=new NpgsqlDataAdapter("SELECT name FROM COMPANY",conn);
			DataSet ds=new DataSet();
			try
			{
			conn.Open();
			da.Fill(ds);
			//for(int i=0;i<ds.Tables[0].Rows.Count;i++)
				//return (ds.Tables[0].Rows[0][0].ToString());
				return ds.Tables[0];
				//return "connection successful";
			}
			catch(Exception e)
			{
				//System.Console.WriteLine(connectionstring.ToString()+"££"+ex.Message+"$$$$$");
				return new DataTable();
				//e.ToString();
			}
			finally
			{conn.Close();}
		}
	}
}

